//效能监督
function xnjdRender(xnjd){
	//事项进驻情况
	xnjd.sxjzqk.ggfwsx==undefined ? $("#ggfwsx").html('0'):$("#ggfwsx").html(xnjd.sxjzqk.ggfwsx);
	xnjd.sxjzqk.xzxksx==undefined ? $("#xzxksx").html('0'):$("#xzxksx").html(xnjd.sxjzqk.xzxksx);
	//业务办理结果监督
	xnjd.ywbljgjd && $("#service_online_all_rate").html(xnjd.ywbljgjd.wsqcbll+'.00%');
	xnjd.ywbljgjd && $("#service_online_rate").html(xnjd.ywbljgjd.wsbjl+'.00%');
	//xnjd.ywbljgjd && $("#service_result_date").text(xnjd.ywbljgjd.rq);
	//异常数统计
	xnjd.ywbljgjd && $("#sxycs-date").text(new Date().getFullYear()+"年数据");
	// efficacy-stat-depth
	  var efficacyStatDepth = echarts.init(document.getElementById('efficacy-stat-depth'))
	  var efficacyStatDepthOption = {
	    color: ['#7AC4FF', '#36A5FF', '#0C86E7', '#0260AE'],
	    tooltip: {
	      trigger: 'item',
	      formatter: "{a} <br/>{b}: {c} ({d}%)"
	    },
	    grid: {
	      left: 0,
	      top: 'middle'
	    },
	    legend: {
	      orient: 'vertical',
	      right: '10%',
	      top: 'middle',
	      itemGap: 20,
	      itemHeight: 10,
	      itemWidth: 10,
	      data:[
	        { name: '0次跑动', icon: 'circle', textStyle: {color: '#9EA9B6'}},
	        { name: '1次跑动', icon: 'circle', textStyle: {color: '#9EA9B6'}},
	        { name: '2次跑动', icon: 'circle', textStyle: {color: '#9EA9B6'}},
	        { name: '≥3次跑动', icon: 'circle', textStyle: {color: '#9EA9B6'}}
	      ]
	    },
	    series: [
	      {
	        name:'在线办理深度',
	        type:'pie',
	        center: ['25%', '50%'],
	        radius: ['30%', '70%'],
	        avoidLabelOverlap: false,
	        hoverOffset: 5,
	        selectedOffset: 5,
	        label: {
	          normal: {
	            show: false,
	            position: 'center'
	          },
	          emphasis: {
	            show: true,
	            textStyle: {
	              fontSize: '12'
	            }
	          }
	        },
	        labelLine: {
	          normal: {
	            show: false
	          }
	        },
	        data:xnjd.zxblsd
	      }
	    ]
	  }
	  efficacyStatDepth.setOption(efficacyStatDepthOption)

	  // efficacy-stat-error
	  var efficacyStatError = echarts.init(document.getElementById('efficacy-stat-error'))
	  var efficacyStatErrorOption = {
	      color: ['#36A5FF', '#FFFFFF'],
	      grid: {
	          left: 0,
	          right: 0,
	          bottom: 30,
	          backgroundColor: '#233e5f'
	      },
	      tooltip: {
	          show: true,
	          trigger: 'axis',
	          formatter: "{b0}月{a0}: {c0}",
	          textStyle: {
	            fontSize: 12
	          }
	        },
	      legend: {
	          left: 0,
	          padding: 10,
	          itemGap: 20,
	          itemHeight: 2,
	          itemWidth: 18,
	          data: [
	              {name: '时效异常数', icon: 'rect', textStyle: {color: '#9EA9B6'}}/*,
	              {name: '收费异常数', icon: 'rect', textStyle: {color: '#9EA9B6'}}*/
	          ]
	      },
	      xAxis: {
	          type: 'category',
	          data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
	          axisTick: { show: false },
	          axisLine: { show: true },
	          axisLabel: {
	              color: '#FFFFFF'
	          }
	      },
	      yAxis: {
	          type: 'value',
	          show: false
	      },
	      series: [
	          {
	              name: '时效异常数',
	              data: xnjd.sxycs,
	              type: 'line'
	          }/*,
	          {
	              name: '收费异常数',
	              data: xnjd.sfycs,
	              type: 'line'
	          }*/
	      ]
	  }
	  efficacyStatError.setOption(efficacyStatErrorOption)
	  $(window).on('resize', function() {
	    efficacyStatDepth.resize()
	    efficacyStatError.resize()
	  });
	//渲染完执行
	swiperXnjd();
}
//接口数据渲染
function renderCustomConfig(data) {
	try{
		//nav
		var homePageTemp = data.data.data;
		//homePageTemp.nav.nav_url && $('#nav_name').attr("href", homePageTemp.nav.nav_url);
		//菜单栏
		var nav_channel_html = [];
		if(homePageTemp.nav.channel){
			$.each(homePageTemp.nav.channel,function(i,channel){
				if(checkStrIsBlank(channel.url) || checkStrIsBlank(channel.name)) {
					return true;
				}
				if(channel.name.indexOf("人民政府") > 0){
					nav_channel_html.push('<li><a href="'+ channel.url +'" target="_blank">' + channel.name + '</a></li>');
				}else{
					nav_channel_html.push('<li><a href="'+ channel.url +'">' + channel.name + '</a></li>');
				}
			})
		}
		$('#login-li').before(nav_channel_html.join(''));
		//banner
		$("#banner_img .hero-welcome-wrapper").css("background-image","url(" + homePageTemp.banner.background + ")");
		homePageTemp.banner.welcome && $(".hero-welcome-title").append(homePageTemp.banner.welcome);
		homePageTemp.banner.slogan && $(".hero-search-title").text(homePageTemp.banner.slogan);
		//登录推荐区
		$("#date").text(showTime());
		var currentTime = new Date(); 
		var hourTime = currentTime.getHours();
		//根据时间控制显示样式
		if(homePageTemp.login.welcome){
			if(hourTime>=8 && hourTime <=11){
				$(".service-toolbar-note").addClass("service-toolbar-"+homePageTemp.login.welcome[0].image);
				$(".service-toolbar-title").text(homePageTemp.login.welcome[0].text);
			}else if(hourTime>=12 && hourTime <=13){
				$(".service-toolbar-note").addClass("service-toolbar-"+homePageTemp.login.welcome[1].image);
				$(".service-toolbar-title").text(homePageTemp.login.welcome[1].text);
			}else if(hourTime>=14 && hourTime <=17){
				$(".service-toolbar-note").addClass("service-toolbar-"+homePageTemp.login.welcome[2].image);
				$(".service-toolbar-title").text(homePageTemp.login.welcome[2].text);
			}else if((hourTime>=18 && hourTime <=24)||(hourTime>=0 && hourTime<8)){
				$(".service-toolbar-note").addClass("service-toolbar-"+homePageTemp.login.welcome[3].image);
				$(".service-toolbar-title").text(homePageTemp.login.welcome[3].text);
			}
		}
		var c = [];
		var s = [];
		//var c1 = [];
		if(homePageTemp.login.services && homePageTemp.login.services.length>0){
			if(homePageTemp.login.services.length>4){
				s.push('<div class="dropdown service-toolbar-links-more">') 
				s.push('<a class="dropdown-toggle" data-toggle="dropdown"><i class="icon icon-down"></i></a><ul class="dropdown-menu">') 
				$.each(homePageTemp.login.services,function(i,res){
					if(i>=4){
						s.push('<li><a title="'+res.name+'" target="_blank" href="'+res.url+'">'+res.name+'</a></li>');
					}else{
						c.push('<a title="'+res.name+'" target="_blank" href="'+res.url+'" class="service-toolbar-links-item">'+res.name+'</a>');
					}
				});
				s.push('</ul></div>');
				$(".service-toolbar-links").html(c.join(''));
				$(".service-toolbar-links").append(s.join(''));
			}else{
				$.each(homePageTemp.login.services,function(i,res){
					c.push('<a href="'+res.url+'" rel="nofollow" class="service-toolbar-links-item">'+res.name+'</a>');
				});
				$(".service-toolbar-links").html(c.join(''));
			}

			/*$.each(homePageTemp.login.services,function(i,res){
				c1.push('<li><a href="'+res.url+'" data-id="u'+i+'" class="service-toolbar-links-item" title="'+res.name+'">'+res.name+'</a></li>');
			});
			$("#portal_service-toolbar-links").html(c1.join(''));*/
		}else{
			$("#window_index_login").remove();
		}
		//常用服务
		var service = []
		$.each(homePageTemp.banner.services_company, function(j, item) {
			if(item.isUrl == 1){
				if(jQuery.type(item.url) === "string"){
					service.push('<li><a title="'+item.name+'" href="'+item.url+'" rel="nofollow">'+item.name+'</a></li>');
				}else{
					var b = JSON.stringify(item.url);
					service.push('<li><a title="'+item.name+'" onclick=urlBindCity('+b+',this) href="javascript:void(0);" data-toggle="modal" data-target="#modal-citylist">'+n.name+'</a></li>');
				}
			}else{
				if(region != 440000){
					var lvUrl = ctx + '/lv3/hot?region='+region+'&type=company&id='+item.id+'&area_code='+region+'&lv1_code='+item.root_id+'&lv1_name='+encodeURIComponent(item.root_name)+'&lv2_name='+encodeURIComponent(item.name);																
					service.push('  <li><a title="'+item.name+'" href="'+lvUrl+'">' + item.name
					+ '</a></li>');
				}else{
					service.push('<li><a title="'+item.name+'" data-toggle="modal" data-target="#modal-citylist" href="javascript:void(0);" onclick=getCity(\''
							+ item.id + '\',"'+region+'","'+item.root_name+'","'+item.root_id+'","'+item.name+'","company") data-id="u1">' + item.name
							+ '</a></li>');
				}
				
			}
			
			
		});
		$.each(homePageTemp.banner.services_person, function(j, item) {
			
			if(item.isUrl == 1){
				if(jQuery.type(item.url) === "string"){
					service.push('<li><a title="'+item.name+'" target="_blank" href="'+item.url+'" rel="nofollow">'+item.name+'</a></li>');
				}else{
					var b = JSON.stringify(item.url);
					service.push('<li><a title="'+item.name+'" onclick=urlBindCity('+b+',this) href="javascript:void(0);" data-toggle="modal" data-target="#modal-citylist">'+n.name+'</a></li>');
				}
			}else{
				if(region != 440000){
					var lvUrl = ctx + '/lv3/hot?region='+region+'&type=person&id='+item.id+'&area_code='+region+'&lv1_code='+item.root_id+'&lv1_name='+encodeURIComponent(item.root_name)+'&lv2_name='+encodeURIComponent(item.name);											
					service.push('  <li><a title="'+item.name+'" href="'+lvUrl+'">' + item.name
					+ '</a></li>');
				}else{
					service.push('<li><a title="'+item.name+'" data-toggle="modal" data-target="#modal-citylist" href="javascript:void(0);" onclick=getCity(\''
							+ item.id + '\',"'+region+'","'+item.root_name+'","'+item.root_id+'","'+item.name+'","person") data-id="u1">' + item.name
							+ '</a></li>');
				}
				
			}
		});
		$(".hero-universal-links").html(service.join(""));

		//便民利企
		var html_zszb = [];
		if(homePageTemp.column.cards && homePageTemp.column.cards.length>0){
			$("#bmlq-title").text(homePageTemp.column.name)
			$.each(homePageTemp.column.cards,function(j, item) {
				var desc = '';
				if(item.desc.length>25){
					desc = item.desc.substring(0,24) + '...'
				}else{
					desc = item.desc;
				}
				html_zszb.push('<div class="swiper-slide gd-col-3">');
				html_zszb.push(  '<div class="portal-gallery-col">');
				html_zszb.push(    '<a target="_blank" href="'+item.url+'" class="portal-gallery-item">');
				html_zszb.push(      '<div class="portal-gallery-cover">');
				html_zszb.push(        '<img src="'+item.image+'" alt="'+item.title+'">');
				html_zszb.push(      '</div>');
				html_zszb.push(      '<div class="portal-gallery-info">');
				html_zszb.push(        '<span class="portal-gallery-title" title="'+item.title+'">');
				html_zszb.push(          item.title);
				html_zszb.push(        '</span>');
				html_zszb.push(        '<span class="portal-gallery-desc" title="'+item.desc+'">');
				html_zszb.push(          desc);
				html_zszb.push(        '</span>');
				html_zszb.push(      '</div>');
				html_zszb.push(    '</a>');
				html_zszb.push(  '</div>');
				html_zszb.push('</div>');
				$("#zszb").html(html_zszb.join(""));
			});
			swiperBmlq();
		}else{
			$("#bmlq").hide();
		}
		//法人、个人
		var html_person = [];
		$.each(homePageTemp.service.person,
			function(j, item) {
				var url = ctx + "/personal/mattersLv2/hot?region="+region+"&lv2code=" + item.id;
				var name = item.name;
				var describe = item.describe;
				if(j <= 7){
					if(item.isUrl == 1){
						url = item.url;
					}
					html_person.push('<div class="bizcard-col gd-col gd-col-3">');
					html_person.push('<div data-href="'+url+'" class="bizcard-item">');
					html_person.push('<svg class="icon-spec" aria-hidden="true"><use xlink:href="#icon-'+item.icon+'"></use></svg>');
					html_person.push('<div class="bizcard-info"><div class="bizcard-title">'
									+ name
									+ '</div><div class="bizcard-desc">');
					$.each(item.items,function(i,n){
						var a = [];
						//html.push('<a class=".bizcard-item-a" onclick=getCity("'+codeStr2+'",this)>'+n.name+'</a>  |  ');
						if(n.isUrl == 1){
							if(jQuery.type(n.url) === "string"){
								html_person.push('<a href="'+n.url+'" target="_blank" rel="nofollow">'+n.name+'</a>');
							}else{
								var b = JSON.stringify(n.url);
								html_person.push('<a onclick=urlBindCity('+b+',this) href="javascript:void(0);" data-toggle="modal" data-target="#modal-citylist">'+n.name+'</a>');
							}
						}else{
							if(region != 440000){
								var lvUrl = ctx + '/lv3/hot?region='+region+'&type=person&id='+n.id+'&area_code='+region+'&lv1_code='+n.root_id+'&lv1_name='+encodeURIComponent(n.root_name)+'&lv2_name='+encodeURIComponent(n.name);																			
								html_person.push('  <a href="'+lvUrl+'">' + n.name
								+ '</a>');
							}else{
								html_person.push('  <a data-toggle="modal" data-target="#modal-citylist" href="javascript:void(0);" onclick=getCity(\''
								+ n.id + '\',"'+region+'","'+n.root_name+'","'+n.root_id+'","'+n.name+'","person") data-id="u1">' + n.name
								+ '</a>');
							}
							
						}
						if(i != item.items.length - 1){
							html_person.push('  |  ');
						}
					})				
					html_person.push('</div></div></div></div>');
				}
			});
		html_person.push('<div class="bizcard-col gd-col gd-col-3">');
		html_person.push('<div data-href="'+ctx+'/personal/hot?region='+region+'" class="bizcard-item">');
		html_person.push('<svg class="icon-spec" aria-hidden="true"><use xlink:href="#icon-gengduoshixiang"></use></svg>');
		html_person.push('<div class="bizcard-info"><div class="bizcard-title">'
						+ "更多"
						+ '</div><div class="bizcard-desc">'
						+ '办理更多个人业务</div>');
		html_person.push('</div></div></div>');
		$("#person-service").html(html_person.join(""));
		var html_company = [];
		$.each(homePageTemp.service.company,
			function(j, item) {
				var url = ctx
						+ "/legal/mattersLv2/hot?region="+region+"&lv2code="
						+ item.id;
				var name = item.name;
				if(j <= 7){
					if(item.isUrl == 1){
						url = item.url;
					}
					html_company.push('<div class="bizcard-col gd-col gd-col-3">');
					html_company.push('<div data-href="'+url+'" class="bizcard-item">');
					html_company.push('<svg class="icon-spec" aria-hidden="true"><use xlink:href="#icon-'+item.icon+'"></use></svg>');
					html_company.push('<div class="bizcard-info"><div class="bizcard-title">'
									+ name
									+ '</div><div class="bizcard-desc">');
					$.each(item.items,function(i,n){
						var a = [];
						var codeStr2 = "";
						if(n.isUrl == 1){
							if(jQuery.type(n.url) === "string"){
								html_company.push('<a href="'+n.url+'" target="_blank" rel="nofollow">'+n.name+'</a>');
							}else{
								var b = JSON.stringify(n.url);
								html_company.push('<a onclick=urlBindCity('+b+',this) href="javascript:void(0);" data-toggle="modal" data-target="#modal-citylist">'+n.name+'</a>');
							}
						}else{
							if(region != 440000){
								var lvUrl = ctx + '/lv3/hot?region='+region+'&type=company&id='+n.id+'&area_code='+region+'&lv1_code='+n.root_id+'&lv1_name='+encodeURIComponent(n.root_name)+'&lv2_name='+encodeURIComponent(n.name);																								
								html_company.push('  <a href="'+lvUrl+'">' + n.name + '</a>');
							}else{
								html_company.push('  <a data-toggle="modal" data-target="#modal-citylist" href="javascript:void(0);" onclick=getCity(\''
								+ n.id + '\',"'+region+'","'+n.root_name+'","'+n.root_id+'","'+n.name+'","company") data-id="u1">' + n.name
								+ '</a>');
							}
						}
						if(i != item.items.length - 1){
							html_company.push('  |  ');
						}
					})
					html_company.push('</div></div></div></div>');
				}
			});
		html_company.push('<div class="bizcard-col gd-col gd-col-3">');
		html_company.push('<div data-href="'+ctx+'/legal/hot?region='+region+'" class="bizcard-item">');
		html_company.push('<svg class="icon-spec" aria-hidden="true"><use xlink:href="#icon-gengduoshixiang"></use></svg>');
		html_company.push('<div class="bizcard-info"><div class="bizcard-title">'
						+ "更多"
						+ '</div><div class="bizcard-desc">'
						+ '办理更多法人业务</div>');
		html_company.push('</div></div></div>');
		$("#company-service").html(html_company.join(""));
		//便民服务
		var bmfw = [];
		if(homePageTemp.convenience.items && homePageTemp.convenience.items.length>0){
			$("#bmfw-title").text(homePageTemp.convenience.name)
			
			var bmfwItems = homePageTemp.convenience.items;
			var eleDivCount = 12; //div*2元素个数
			var eleDivRowCount = 4; //div*2一行的元素个数
			var divNum = (bmfwItems.length % eleDivCount) == 0 ?
					parseInt((bmfwItems.length / eleDivCount)) : 
						parseInt((bmfwItems.length / eleDivCount)) + 1; //几个div*2（div成对出现）
			var row = (bmfwItems.length % eleDivRowCount == 0 ) ? 
					parseInt(bmfwItems.length / eleDivRowCount) : 
						parseInt(bmfwItems.length / eleDivRowCount) + 1; //一共多少行
			if (row > 3) {
				row = 3; //最多只有3行
			}
			
			for(var i=1; i<=divNum; ++i) {
				bmfw.push('<div class="swiper-slide gd-col gd-col-6"><div class="gd-row gd-row-md-6">');
				for(var j=1; j<=row; ++j) { 
					var bmfwIndex = (i-1)*eleDivCount + (j-1)*eleDivRowCount;
					for(var z=0; z<2; ++z) { //每行2个
						if(bmfwIndex + z < bmfwItems.length) {
							bmfw.push('<div class="gd-col gd-col-6"><a href="'+bmfwItems[bmfwIndex + z].url+'" target="_blank" class="portal-service-link">'+bmfwItems[bmfwIndex + z].name+'</a></div>');
						}
					}
				}
				bmfw.push('</div></div>');
				
				bmfw.push('<div class="swiper-slide gd-col gd-col-6"><div class="gd-row gd-row-md-6">');
				for(var j=1; j<=row; ++j) { 
					var bmfwIndex = (i-1)*eleDivCount + (j-1)*eleDivRowCount;
					for(var z=0; z<2; ++z) { //每行2个
						if(bmfwIndex + z + 2 < bmfwItems.length) {
							bmfw.push('<div class="gd-col gd-col-6"><a href="'+bmfwItems[bmfwIndex + z + 2].url+'" target="_blank" class="portal-service-link">'+bmfwItems[bmfwIndex + z + 2].name+'</a></div>');
						}
					}
				}
				bmfw.push('</div></div>');
			}
			
			$("#bmfw").append(bmfw.join(''));
			swiperBmfw();
		}else {
			$("#bmfw-div").hide();
		}
		//菜单栏
		var navigation = [];
		var nUrl = location.origin || location.href.substring(0,location.href.indexOf(location.host)) + location.host;
		$.each(homePageTemp.nav.menu,function(i,menu){
			//如果跳转的地址为外部链接时需要打开新窗口 (由于个性化配置问题，这段代码不适用于本地与集成，各开发可以删掉，但不要提交)
			if(menu.url.indexOf(nUrl) != -1 || menu.url.indexOf("http") == -1){
				navigation.push('<li><a href="'+menu.url+'" >'+menu.name+'</a></li>');
			}else{
				navigation.push('<li><a href="'+menu.url+'" target="_blank">'+menu.name+'</a></li>');
			}
		});
	    $(".navigation").append(navigation.join(''));
		// 菜单高亮
		changeHeaderNavHover(index);
		//侧边栏
		var sidebar = [];
		if(homePageTemp.sidebar.menu){	  
	    	$("#affix-toolbar").show();
			$.each(homePageTemp.sidebar.menu, function(i, menu) {
				var menu_url = menu.url;
				var menu_text = menu.text;
				var menu_qr = menu.qr;
				// 说明是本应用服务
				if(!checkStrIsBlank(menu_url) && menu_url.indexOf(location.host) > -1) {
					if (menu_qr == "consult") {
						sidebar.push('<li class="affix-toolbar-item"><a title='+menu_text+'  href="'+menu_url+'" id="complainError-1">'
								+'<i class="icon icon-'+menu.icon+'"></i><span>'+ menu_text + '</span></a></li>');
						return true;
					} else if(menu_qr == "complain") {
						sidebar.push('<li class="affix-toolbar-item"><a title='+menu_text+' data-toggle="modal" data-target="#complainError2" href="'+menu_url+'" id="complainError-2">'
								+'<i class="icon icon-'+menu.icon+'"></i><span>'+ menu_text + '</span></a></li>');
						return true;
					}
				}
				sidebar.push('<li class="affix-toolbar-item"><a title='+menu_text+' target="_blank" href="'+menu_url+'">'
						+'<i class="icon icon-'+menu.icon+'"></i><span>'+ menu_text + '</span></a></li>');
			});
		
			$("#affix-toolbar").empty();
			$("#affix-toolbar").append(sidebar.join(''));
		}else{
	    	$("#affix-toolbar").hide();
	    }
		if(handleStr(homePageTemp.footer.sitecode)!=""){
			var currentUrl = encodeURIComponent(window.location.href);
			$("#support-link-id").attr("href", "http://121.43.68.40/exposure/jiucuo.html?"+
				"site_code="+homePageTemp.footer.sitecode+"&url="+currentUrl);  
		}
		
		//渲染页脚联系电话跟联系信息url
		$(".footer-contact-tel").append(homePageTemp.footer.telphone);
		if (homePageTemp.footer.contact) {
			$("#footer-lxxx-url").attr("href", String(homePageTemp.footer.contact));
		} else {
			$("#footer-lxxx-url").attr("onclick", "javascript: void(0);");
		}
	}catch(e){
		console && console.log(e);
	}
}
//swiper分页
function swiperBmlq(){
	  var gallerySwiper = $('.portal-gallery').addSwiper({
	    col: {
	      SM: 1,
	      MD: 2,
	      LG: 4
	    },
	    onSlideChangeStart: function(swiper) {
	        $(swiper.container).closest('.swiper-container-wrapper').css('overflow', 'hidden')
	    },
	    onSlideChangeEnd: function(swiper) {
	        $(swiper.container).closest('.swiper-container-wrapper').css('overflow', 'visible')
	    }
	  });
	  $('.portal-gallery').find('img').eq(0).on('load', function() {
		  gallerySwiper.reset();
	  });
}

function swiperBmfw(){
	  $('.portal-service').addSwiper({
	    col: {
	      SM: 1,
	      MD: 2
	    }
	  });
}
function swiperXnjd(){
	  $('.efficacy-stat-swiper').addSwiper({
	    col: {
	      SM: 1,
	      MD: 2,
	      LG: 3
	    }
	  });

}